package cn.aresoft.framework.plugins.pagination.jdbc;

/**
 *  <p>Title: PageBean</p>
 *  <p>Description: PageBean</p>
 *  <p>Copyright: Copyright (c) 2009-9-1</p>
 *  <p>Company: SHANGHAI IDEAL INFORMATION UNDUSTRY(GROUP) Co.,LTD</p>
 *
 * @author shig
 */

public class PageBeanJ {
    private int count = 0; 

    private int pageSize = 10;

    private int pageCount = 0; 

    private int page = 1; 

    private String listSQL;

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        if (pageSize != 0) {
            pageCount = count / pageSize;
            if (count % pageSize != 0) {
                pageCount++;
            }
        }
        this.count = count;
    }

    public String getListSQL() {
        return listSQL;
    }

    public void setListSQL(String listSQL) {
        this.listSQL = listSQL;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

	
	/**
	 * 显示用的分页信息
	 */
	public String getToolsMenu() {

		StringBuffer str = new StringBuffer("");
		int next, prev;
		prev = page - 1;
		next = page + 1;
		
		if (page > 1) {
			str.append("<a href=\"#\" onclick=\"document.forms[0].jumpPage.value=1;document.forms[0].submit();\">首页</a> ");
		} else {
			str.append("首页 ");
		}
		
		if (page > 1) {
			str.append("<a href=\"#\" onclick=\"document.forms[0].jumpPage.value="
							+ prev + ";document.forms[0].submit();\">上页</a> ");
		} else {
			str.append("上页 ");
		}
		if (page < pageCount) {
			str.append("<a href=\"#\" onclick=\"document.forms[0].jumpPage.value="
							+ next + ";document.forms[0].submit();\">下页</a> ");
		} else {
			str.append("下页 ");
		}
		if (pageCount > 1 && page != pageCount) {
			str.append("<a href=\"#\"  onclick=\"document.forms[0].jumpPage.value="
							+ pageCount
							+ ";document.forms[0].submit();\">末页</a>  ");
		} else {
			str.append("末页  ");
		}
		str.append(" 共" + count + "条记录");
		str.append("  每页<SELECT size=1 name=pagesize onchange=\"document.forms[0].jumpPage.value=1; document.forms[0].pageSize.value=this.value; document.forms[0].submit();\">");

		if (pageSize == 10) {
			str.append("<OPTION value=10 selected>10</OPTION>");
		} else {
			str.append("<OPTION value=10>10</OPTION>");
		}
		if (pageSize == 20) {
			str.append("<OPTION value=20 selected>20</OPTION>");
		} else {
			str.append("<OPTION value=20>20</OPTION>");
		}
		if (pageSize == 50) {
			str.append("<OPTION value=50 selected>50</OPTION>");
		} else {
			str.append("<OPTION value=50>50</OPTION>");
		}
		if (pageSize == 100) {
			str.append("<OPTION value=100 selected>100</OPTION>");
		} else {
			str.append("<OPTION value=100>100</OPTION>");
		}
		str.append("</SELECT>");
		str.append("条 分" + pageCount + "页显示 转到");
		str.append("<SELECT size=1 name=Pagelist onchange=\"document.forms[0].jumpPage.value=this.value;document.forms[0].submit();\">");
		for (int i = 1; i < pageCount + 1; i++) {
			if (i == page) {
				str.append("<OPTION value=" + i + " selected>" + i
						+ "</OPTION>");
			} else {
				str.append("<OPTION value=" + i + ">" + i + "</OPTION>");
			}
		}
		str.append("</SELECT>页");
		str.append("<INPUT type=hidden  value=" + page
				+ " name=\"pages\" > ");
		str.append("<INPUT type=hidden  value=" + pageSize
				+ " name=\"pageSize\"> ");
		str.append("<INPUT type=hidden  value=\"\" name=\"jumpPage\"> ");
		
		return str.toString();

	}
}


